package org.example.hansp.collection_.list_;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
@SuppressWarnings({"all"})
public class ListSource {
    public static void main(String[] args) {
        List list = new ArrayList();
        list.add(new Book("人间便利店","frank",78.9));
        list.add(new Book("如何孤独终老","kral",88.9));
        list.add(new Book("java语言程序设计","jhon",98.9));

     /*   list.sort(new Comparator<Book>() {
            public int compare(Book o1, Book o2) {
                double d1 = o1.getPrice() - o2.getPrice();
                if(d1 < 0){
                    return -1;
                }else if(d1 > 0){
                    return 1;
                }
                else{
                    return 0;
                }
            }
        });*/

        for(int i=0; i<list.size(); i++){
            for(int j=i+1;j<list.size();j++){
              Book book1 =(Book) list.get(i);
              Book book2 =(Book) list.get(j);
              if(book1.getPrice()-book2.getPrice()>0){
                  list.set(i,book2);
                  list.set(j,book1);
              }
            }
        }
        for(Object o : list){
            System.out.println(o.toString());
        }

    }
}
class Book{
    private String title;
    private String author;
    private double price;

    @Override
    public String toString() {
        return
                "title='" + title + '\'' +'\t'+
                ", author='" + author + '\'' +'\t'+
                ", price=" + price;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getAuthor() {
        return author;
    }

    public void setAuthor(String author) {
        this.author = author;
    }

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public Book(String title, String author, double price) {
        this.title = title;
        this.author = author;
        this.price = price;
    }
}
